<template>
    <h2>添加理财信息</h2>
<table border="1">
    <tr>
        <td>理财项目名称</td>
        <td><input type="text" v-model="info.F_Name"></td>
    </tr>
    <tr>
        <td>年收益</td>
        <td><input type="text" v-model="info.F_ARY"></td>
    </tr>
    <tr>
        <td>最低金额</td>
        <td><input type="text" v-model="info.F_MinMoney"></td>
    </tr>
    <tr>
        <td>风险等级</td>
        <td><input type="radio" name="Flevel" value="0" checked>低风险
        <input type="radio" name="Flevel" value="1">中风险
        <input type="radio" name="Flevel" value="2">高风险
        
        </td>
    </tr>
    <tr>
        <td>理财利率</td>
        <td>
            <select name="" id="" v-model="info.I_Id">
                <option value="0">--请选择--</option>
                <option v-for="i in InterestInfo" :value="i.I_Id">{{ i.I_Year }}年利率为{{ i.I_Interest }}%</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button @click="SaveData" class="btn btn-success" >保存</button>
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';
const info=ref({
    F_Name:'',
    F_ARY:'',
    F_MinMoney:'',
    F_Number:'',
    F_Level:0,
    I_Id:0,

});
//创建理财利息响应式数据
const InterestInfo=ref([{
    I_Id:0,
    I_Interest:0,
    I_Year:0
}])
onMounted(()=>{
    LoadInterest()
})
//完成基本理财信息加载
const LoadInterest=()=>{
    axios.get("https://localhost:44358/api/Finan/ShowInterest",{
       
    }).then(res=>{
        InterestInfo.value=res.data
    }).catch(err=>{
        console.log(err);
    })
}
const SaveData=()=>{
    //验证非空
    if(info.value.F_Name==''){
        alert("理财名称不能为空")
        return;
    }
    //验证理财最低金额需大于0元且小于1亿元
    if(Number(info.value.F_MinMoney )>100000000||Number(info.value.F_MinMoney )<0){
        alert("验证理财最低金额需大于0元且小于1亿元")
        return
    }
    //发送请求
    axios.post("https://localhost:44358/api/Finan/AddFinanInfo",
        {
            F_Name:info.value.F_Name,
            F_ARY:info.value.F_ARY,
            F_MinMoney:info.value.F_MinMoney,
            F_Level:info.value.F_Level,
            I_Id:info.value.I_Id
        }
    ).then(res=>{
        console.log(res.data);
        if(res.data>0){
            alert("理财项目信息保存成功")
        }else if(res.data==-1){
            alert("理财产品名称重复")
        }else{
            alert("添加失败")
        }
    }).catch(err=>{
        console.log(err);
    })
}

</script>